package com.yanggu.scala.chapater12.for2

//模式匹配-for循环中的模式匹配
object MatchForDemo01 {

  def main(args: Array[String]): Unit = {
    val map = Map[String, Int]("A" -> 1, "B" -> 0, "C" -> 3)

    for ((k, v) <- map) {
      println(k + " -> " + v)
    }

    println("--------------(k, 0)-------------")
    //这里只用当value为0时, 才进行for循环里面的内容
    for ((k, 0) <- map) {
      println(k + " -> " + 0)
    }

    println("-------------(k, v) <- map if v = 0--------------")
    for ((k, v) <- map if v == 1) {
      println(k + " -> " + v)
    }
  }

}
